let that,
  api = new (require('../../utils/api.js')),
  util = new (require('../../utils/util.js')),
  // imghead = api.getimgurl(),
  headimg = api.getimgurl(),
  app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    disposiysums: [
      {
        name: '未退押金',
      }, 
      {
        name: '已退押金',
      }, 
      ],
    isCollect: false,
    currentTab: 0,
    currentageindex: 0,
    pagesize:20,
    start:0,
    state:'UNRETURN',
    list:[]
  },
 tabtap(e){
   let {index} = e.currentTarget.dataset,{state}=that.data;
   console.log(index,'index');
   if(index==0){
    state='UNRETURN'
   }else{
    state='RETURNED'
   }
   this.setData({currentageindex:index,state},()=>{
    that.getdata()
   })

 } ,
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options, 'options');
    that = this;
    that.getdata()
  //   let { disposiysums } = this.data;
  //   that.getdata();
  //  disposiysums.map((x, i) => {
  //     disposiysums[i]['collect'] = 0
  //   })
  //   that.setData({ disposiysums, currentageindex: options.i || 0 })
  
  },
  todetail(e){
    let {index} = e.currentTarget.dataset;
    wx.navigateTo({
      url: '../depositdetail/depositdetail?i='+index,
    })
  },
  getdata(){
    let { start,pagesize,list} = this.data
    api.getdepositlist({ start, pagesize},res=>{
      if(res.data.issuccess==1){
           res.data.list.forEach(x=>{
             x.borrowDate = util.formatDate(new Date(x.item.borrowDate));
             x.backDate = util.formatDate(new Date(x.item.backDate));
             x.createDate = util.formatTime(new Date(x.item.createDate));
             x.payDate = util.formatDate(new Date(x.item.payDate));
            //  x.statecontent = getstatecontent(x.item.state);
             x.total = x.item.total/100;
             x.deposit = x.item.deposit/100;
             if(x.books){
               x.books.forEach((y,z)=>{
                 if (y.goodsimg.indexOf("http")== -1) {
                   y.thumbPicPath = headimg + y.goodsimg;
                 }else{
                   y.thumbPicPath=y.goodsimg
                 }
               })
             }
             list.push(x)
             that.setData({list,reachbtm:list.length==res.data.total})
           })
        //
        // reslist.map(x=>{
        //   x.date = util.formatTime(new Date(x.updateDate))
        //   x.state = x.state=='UNRETURN'?"未退还":"已退还"
        // })
        // list=list.concat(reslist)
        // that.setData({list})
      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    // let { reachbtm,start, pagesize} = this.data;
    // if (!reachbtm) {
    //   that.setData({ start: start + pagesize }, () => {
    //     this.getdata();
    //   })
    // }

    that.setData({ start: that.data.start + that.data.pagesize }, () => {
      // console.log(that.data.start,'start')
      if (that.data.reachbtm) {
        return
      }
      that.getdata()
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})